package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.godmch.parameter.GetRoleDetailBean;
import com.ymatou.iapi.godmch.parameter.RoleDto;
import com.ymatou.iapi.godmch.service.GetRoleDetailCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.csrole;
import com.ymttest.database.model.permission;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;

/**
*获取角色详细信息
*FreeMaker Template自动生成代码
*/

@TestSuite
public class Ts_GetRoleDetail{
	private static GetRoleDetailBean getroledetailBean;
	private static GetRoleDetailCall getroledetailCall;
	DefGodMchWapper DefGodMchWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取角色详细信息");
	}

	@Before
	public void caseUp() {
		getroledetailBean=new GetRoleDetailBean();
		getroledetailCall=new GetRoleDetailCall();
		DefGodMchWapper=new DefGodMchWapper(); 
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getroledetailCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetRoleDetail_001() {
		Logger.start(true,"获取角色详细信息,成功-销售专员");
		try {
			Integer roleid=1;
			getroledetailBean.setRoleId(roleid);
			getroledetailCall.setData(getroledetailBean);
			getroledetailCall.callService();			
			Logger.verifyEquals("200", getroledetailCall.getString("status"), "验证status");
			csrole csr = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(cs->cs.getRoleId().equals(roleid)).findFirst().get();
			JsonObject result = getroledetailCall.getJsonObject().get("result").getAsJsonObject();
			Logger.verifyEquals(result.get("roleId").getAsInt(), csr.getRoleId(), "验证roleid");
			Logger.verifyEquals(result.get("remark").getAsString(),csr.getRemark(), "验证remark");
			Logger.verifyEquals(result.get("title").getAsString(), csr.getTitle(), "验证title");
			Logger.verifyEquals(result.get("mchId").getAsInt(), csr.getMchId(), "验证MchId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetRoleDetail_002() {
		Logger.start(true,"获取角色详细信息,成功-发货专员");
		try {
			Integer roleid=2;
			getroledetailBean.setRoleId(roleid);
			getroledetailCall.setData(getroledetailBean);
			getroledetailCall.callService();			
			Logger.verifyEquals("200", getroledetailCall.getString("status"), "验证status");
			csrole csr = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(cs->cs.getRoleId().equals(roleid)).findFirst().get();
			JsonObject result = getroledetailCall.getJsonObject().get("result").getAsJsonObject();
			Logger.verifyEquals(result.get("roleId").getAsInt(), csr.getRoleId(), "验证roleid");
			Logger.verifyEquals(result.get("remark").getAsString(),csr.getRemark(), "验证remark");
			Logger.verifyEquals(result.get("title").getAsString(), csr.getTitle(), "验证title");
			Logger.verifyEquals(result.get("mchId").getAsInt(), csr.getMchId(), "验证MchId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetRoleDetail_003() {
		Logger.start(true,"获取角色详细信息,成功-普通运营");
		try {
			Integer roleid=3;
			getroledetailBean.setRoleId(roleid);
			getroledetailCall.setData(getroledetailBean);
			getroledetailCall.callService();			
			Logger.verifyEquals("200", getroledetailCall.getString("status"), "验证status");
			csrole csr = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(cs->cs.getRoleId().equals(roleid)).findFirst().get();
			JsonObject result = getroledetailCall.getJsonObject().get("result").getAsJsonObject();
			Logger.verifyEquals(result.get("roleId").getAsInt(), csr.getRoleId(), "验证roleid");
			Logger.verifyEquals(result.get("remark").getAsString(),csr.getRemark(), "验证remark");
			Logger.verifyEquals(result.get("title").getAsString(), csr.getTitle(), "验证title");
			Logger.verifyEquals(result.get("mchId").getAsInt(), csr.getMchId(), "验证MchId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetRoleDetail_004() {
		Logger.start(true,"获取角色详细信息,成功-高级运营");
		try {
			Integer roleid=4;
			getroledetailBean.setRoleId(roleid);
			getroledetailCall.setData(getroledetailBean);
			getroledetailCall.callService();			
			Logger.verifyEquals("200", getroledetailCall.getString("status"), "验证status");
			csrole csr = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(cs->cs.getRoleId().equals(roleid)).findFirst().get();
			JsonObject result = getroledetailCall.getJsonObject().get("result").getAsJsonObject();
			Logger.verifyEquals(result.get("roleId").getAsInt(), csr.getRoleId(), "验证roleid");
			Logger.verifyEquals(result.get("remark").getAsString(),csr.getRemark(), "验证remark");
			Logger.verifyEquals(result.get("title").getAsString(), csr.getTitle(), "验证title");
			Logger.verifyEquals(result.get("mchId").getAsInt(), csr.getMchId(), "验证MchId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetRoleDetail_005() {
		Logger.start(true,"不输入roleId失败");
		try {
			getroledetailCall.setData(getroledetailBean);
			getroledetailCall.callService();			
			Logger.verifyEquals("4001", getroledetailCall.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}